<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <input type="text" id="ceshi">
    <span id="info"></span>
    <script>
        var ceshi = document.querySelector('#ceshi')
        var info = document.querySelector('#info')
        ceshi.oninput = function () {
            var val = this.value;
            var check = function (value,cb) {
                //长度必须要超过5
                setTimeout(function () {
                    if (value.length > 5) {
                        cb()
                    } else {
                        cb(new Error('长度必须超过5'))
                    }
                }, 1000)
            }

            check(val,function(err){
                if(!err){
                    info.innerHTML = '验证通过'
                    info.style.color = 'green'
                }else{
                    info.innerHTML = '验证失败'
                    info.style.color = 'red'
                }
            })
            // var checkResult = check(val)//undefined
            // console.log(checkResult)
            // if (checkResult == true) {
            //     info.innerHTML = '验证通过'
            //     info.style.color = 'green'
            // } else {
            //     info.innerHTML = '验证失败'
            //     info.style.color = 'red'
            // }
        }
    </script>
</body>

</html>